/*MyPhotoIndex Free Photo Organizer <www.myphotoindex.com>
  Copyright (C) <2006-2009>  <Asaf Yarkoni asaf@yarkoni.net>

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.*/
using System;
using System.Collections.Generic;
using System.Text;

namespace MyPhotoIndex.ImageBank.Query
{
    public enum QueryParameterRelation { And = 0, Or = 1 }
    public enum QueryParameterOperation { Equal = 0, NotEqual, GreaterThen, GreaterThenEquals, LessThen, LessThenEquals}

    public abstract class QueryParameter
    {
        private QueryParameterRelation m_relation;
        private QueryParameterOperation m_operation;
        private string m_propertyPath;
        private bool m_compareParent;

        public QueryParameterRelation Relation
        {
            get { return m_relation; }
            set { m_relation = value; }
        }

        public QueryParameterOperation Operation
        {
            get { return m_operation; }
            set { m_operation = value; }
        }

        public virtual string PropertyPath
        {
            get { return m_propertyPath; }
            set { m_propertyPath = value; }
        }

        public bool CompareParent
        {
            get { return m_compareParent; }
            set { m_compareParent = value; }
        }

        public abstract bool GreaterThen(Object value);

        public abstract bool LessThen(Object value);

        public abstract bool LessThenEquals(Object value);
    }

    public abstract class QueryParameter<T> : QueryParameter
    {
        private T                           m_parameterData;

        public virtual T ParameterData
        {
            get { return m_parameterData; }
            set { m_parameterData = value; }
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        public override bool Equals(Object value)
        {
            return (m_parameterData.ToString().CompareTo(value) == 0);
        }

        public override bool GreaterThen(Object value)
        {
            return (m_parameterData.ToString().CompareTo(value) > 0);
        }

        public override bool LessThen(Object value)
        {
            return (m_parameterData.ToString().CompareTo(value) < 0);
        }

        public override bool LessThenEquals(Object value)
        {
            return (m_parameterData.ToString().CompareTo(value) <= 0);
        }
    }
}
